<?php
$this->Html->addCrumb('Gallery', '/gallery');
if(isset($companyInfo) && !empty($companyInfo)) {
  $this->Html->addCrumb($companyInfo['Company']['name']);
}
//CSS

//Javascript

$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){

      var tag = document.createElement("script");
      tag.src = "//www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName("script")[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      var numVideos = $("[data-video=video]").size();
      for (var i=0; i<numVideos; i++) {
      var "player" + i;
        function onYouTubeIframeAPIReady() {
          "player" + i = new YT.Player("player" + i);
        }
      }

      function onPlayerReady(event) {
        event.target.playVideo();
      }

        });
       ';
$this->Html->scriptEnd();
?>

<h1 class="pageTitle">Video Gallery</h1>

<?php if(!empty($companyInfo)) {
  echo '<h2 id="albumCategoryHeader">'.$companyInfo['Company']['name'].'</h2>';
}?>


<?php
  if (isset($videos) && !empty($videos)) {
    $count=1;
    foreach ($videos as $rec) {
      //echo '<div>';
      $lastUpdated = new DateTime($rec['Video']['modified']);
      $youtubeId = $rec['Video']['youtube_param'];
      ?>
    <div class="row-fluid" style="z-index: -10;" data-video="video">
      <div class="span12">
          <iframe id="player<?php echo $count;?>" type="text/html" width="600" height="445"
          src="http://www.youtube.com/embed/<?php echo $youtubeId;?>?enablejsapi=1"
          frameborder="0"></iframe>
      </div>
    </div>

    <div class="row-fluid" style="margin-bottom:30px;">
      <div class="span12">
        <p><?php echo $rec['Video']['description'];?></p>
      </div>
    </div>

      <?php

      $count++;
      if($count!==0 && $count%2==0) {
        echo '<div class="clear"></div>';
      }
    }?>

    <div class="row-fluid" >
      <div class="span12">
        <?php echo $this->element('main_pagination');?>
      </div>
    </div>

    <?php
  }
?>